package com.ys.servers.points.dao.impl;

import com.ys.servers.common.dao.BasicNoSqlDao;
import com.ys.servers.common.data.UserType;
import com.ys.servers.points.dao.UserPointsDataDao;
import com.ys.servers.points.data.UserPointsData;
import io.vertx.core.Future;

/**
 * Created by taotao on 2017/5/10.
 */
public class UserPointsDataDaoImpl extends BasicNoSqlDao<UserPointsData> implements UserPointsDataDao {

    @Override
    public Future<UserPointsData> getUserPointsData(long userId, UserType userType) {
        return this.getData(userType.ordinal() + ":" + userId, UserPointsData.class);
    }

    @Override
    public Future<UserPointsData> addUserPointsData(long userId, UserType userType) {
        UserPointsData userPointsData = new UserPointsData();
        userPointsData.setId(userType.ordinal() + ":" + userId);
        return this.addData(userPointsData.setUpdateTime(System.currentTimeMillis()).setUserId(userId)
                .setUserType(userType));
    }

    @Override
    public Future<UserPointsData> saveUserPointsData(UserPointsData userPointsData) {
        userPointsData.setId(userPointsData.getUserType().ordinal() + ":" + userPointsData.getUserId());
        return this.addData(userPointsData);
    }

}
